<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>FabGL: Others/KeyboardVirtualKeys/KeyboardVirtualKeys.ino</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">FabGL
   </div>
   <div id="projectbrief">ESP32 Display Controller and Graphics Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('_others_2_keyboard_virtual_keys_2_keyboard_virtual_keys_8ino-example.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Others/KeyboardVirtualKeys/KeyboardVirtualKeys.ino</div>  </div>
</div><!--header-->
<div class="contents">
<p>PS/2 keyboard virtual keys</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment">  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - &lt;http://www.fabgl.com&gt;</span></div><div class="line"><span class="comment">  Copyright (c) 2019-2021 Fabrizio Di Vittorio.</span></div><div class="line"><span class="comment">  All rights reserved.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">* Please contact fdivitto2013@gmail.com if you need a commercial license.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">* This library and related software is available under GPL v3.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is free software: you can redistribute it and/or modify</span></div><div class="line"><span class="comment">  it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment">  the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><span class="comment">  (at your option) any later version.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment">  but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment">  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div><div class="line"><span class="comment">  GNU General Public License for more details.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment">  along with FabGL.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="fabgl_8h.html">fabgl.h</a>&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><a name="_a0"></a><a class="code" href="classfabgl_1_1_v_g_a16_controller.html">fabgl::VGA16Controller</a>   DisplayController;</div><div class="line"><a name="_a1"></a><a class="code" href="classfabgl_1_1_terminal.html">fabgl::Terminal</a>          Terminal;</div><div class="line"><a name="_a2"></a><a class="code" href="classfabgl_1_1_p_s2_controller.html">fabgl::PS2Controller</a>     PS2Controller;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> xprintf(<span class="keyword">const</span> <span class="keywordtype">char</span> * format, ...)</div><div class="line">{</div><div class="line">  va_list ap;</div><div class="line">  va_start(ap, format);</div><div class="line">  <span class="keywordtype">int</span> size = vsnprintf(<span class="keyword">nullptr</span>, 0, format, ap) + 1;</div><div class="line">  <span class="keywordflow">if</span> (size &gt; 0) {</div><div class="line">    va_end(ap);</div><div class="line">    va_start(ap, format);</div><div class="line">    <span class="keywordtype">char</span> buf[size + 1];</div><div class="line">    vsnprintf(buf, size, format, ap);</div><div class="line">    Serial.write(buf);</div><div class="line">    Terminal.<a name="a3"></a><a class="code" href="classfabgl_1_1_terminal_a7c66fc8d559f4956d4ccea196299bca7.html#a7c66fc8d559f4956d4ccea196299bca7">write</a>(buf);</div><div class="line">  }</div><div class="line">  va_end(ap);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> printHelp()</div><div class="line">{</div><div class="line">  xprintf(<span class="stringliteral">&quot;\e[93m\n\nPS/2 Keyboard Virtual Keys\r\n&quot;</span>);</div><div class="line">  xprintf(<span class="stringliteral">&quot;Chip Revision: %d   Chip Frequency: %d MHz\r\n&quot;</span>, ESP.getChipRevision(), ESP.getCpuFreqMHz());</div><div class="line"></div><div class="line">  printInfo();</div><div class="line"></div><div class="line">  xprintf(<span class="stringliteral">&quot;Commands:\r\n&quot;</span>);</div><div class="line">  xprintf(<span class="stringliteral">&quot;  1 = US Layout       2 = UK Layout       3 = DE Layout\r\n&quot;</span>);</div><div class="line">  xprintf(<span class="stringliteral">&quot;  4 = IT Layout       5 = ES Layout       6 = FR Layout\r\n&quot;</span>);</div><div class="line">  xprintf(<span class="stringliteral">&quot;  7 = BE Layout\r\n&quot;</span>);</div><div class="line">  xprintf(<span class="stringliteral">&quot;  r = Reset\r\n&quot;</span>);</div><div class="line">  xprintf(<span class="stringliteral">&quot;  q = Scancode set 1  w = Scancode set 2\r\n&quot;</span>);</div><div class="line">  xprintf(<span class="stringliteral">&quot;  l = Test LEDs\r\n&quot;</span>);</div><div class="line">  xprintf(<span class="stringliteral">&quot;Various:\r\n&quot;</span>);</div><div class="line">  xprintf(<span class="stringliteral">&quot;  h = Print This help\r\n\n&quot;</span>);</div><div class="line">  xprintf(<span class="stringliteral">&quot;Use Serial Monitor to issue commands\r\n\n&quot;</span>);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> printInfo()</div><div class="line">{</div><div class="line">  <span class="keyword">auto</span> keyboard = PS2Controller.<a name="a4"></a><a class="code" href="classfabgl_1_1_p_s2_controller_add3a17b29e9908b6e5cca6f52122119b.html#add3a17b29e9908b6e5cca6f52122119b">keyboard</a>();</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (keyboard-&gt;isKeyboardAvailable()) {</div><div class="line">    xprintf(<span class="stringliteral">&quot;Device Id = &quot;</span>);</div><div class="line">    <span class="keywordflow">switch</span> (keyboard-&gt;identify()) {</div><div class="line">      <span class="keywordflow">case</span> PS2DeviceType::OldATKeyboard:</div><div class="line">        xprintf(<span class="stringliteral">&quot;\&quot;Old AT Keyboard\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> PS2DeviceType::MouseStandard:</div><div class="line">        xprintf(<span class="stringliteral">&quot;\&quot;Standard Mouse\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> PS2DeviceType::MouseWithScrollWheel:</div><div class="line">        xprintf(<span class="stringliteral">&quot;\&quot;Mouse with scroll wheel\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> PS2DeviceType::Mouse5Buttons:</div><div class="line">        xprintf(<span class="stringliteral">&quot;\&quot;5 Buttons Mouse\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> PS2DeviceType::MF2KeyboardWithTranslation:</div><div class="line">        xprintf(<span class="stringliteral">&quot;\&quot;MF2 Keyboard with translation\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> PS2DeviceType::M2Keyboard:</div><div class="line">        xprintf(<span class="stringliteral">&quot;\&quot;MF2 keyboard\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">default</span>:</div><div class="line">        xprintf(<span class="stringliteral">&quot;\&quot;Unknown\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    }</div><div class="line">    xprintf(<span class="stringliteral">&quot;  Keyboard Layout: \&quot;%s\&quot;\r\n&quot;</span>, keyboard-&gt;getLayout()-&gt;name);</div><div class="line">  } <span class="keywordflow">else</span></div><div class="line">    xprintf(<span class="stringliteral">&quot;Keyboard Error!\r\n&quot;</span>);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> setup()</div><div class="line">{</div><div class="line">  Serial.begin(115200);</div><div class="line">  delay(500);  <span class="comment">// avoid garbage into the UART</span></div><div class="line">  Serial.write(<span class="stringliteral">&quot;\r\n\nReset\r\n&quot;</span>);</div><div class="line"></div><div class="line">  PS2Controller.<a name="a5"></a><a class="code" href="classfabgl_1_1_p_s2_controller_ab8520612804a921ad834b41214a99c09.html#ab8520612804a921ad834b41214a99c09">begin</a>(PS2Preset::KeyboardPort0);</div><div class="line"></div><div class="line">  DisplayController.begin();</div><div class="line">  DisplayController.<a name="a6"></a>setResolution(<a name="a7"></a><a class="code" href="fabglconf_8h_a2d4571e9072b78877c36bf32bc9423f8.html#a2d4571e9072b78877c36bf32bc9423f8">VGA_640x480_60Hz</a>);</div><div class="line"></div><div class="line">  Terminal.<a name="a8"></a><a class="code" href="classfabgl_1_1_terminal_aebaecc1fa474fddc48dd5778024b19a5.html#aebaecc1fa474fddc48dd5778024b19a5">begin</a>(&amp;DisplayController);</div><div class="line">  Terminal.<a name="a9"></a><a class="code" href="classfabgl_1_1_terminal_aace245bfe6cab7b4339bd691077e1c23.html#aace245bfe6cab7b4339bd691077e1c23">enableCursor</a>(<span class="keyword">true</span>);</div><div class="line"></div><div class="line">  <span class="comment">//PS2Controller.keyboard()-&gt;setTypematicRateAndDelay(33, 500);</span></div><div class="line"></div><div class="line">  printHelp();</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> loop()</div><div class="line">{</div><div class="line">  <span class="keyword">auto</span> keyboard = PS2Controller.<a class="code" href="classfabgl_1_1_p_s2_controller_add3a17b29e9908b6e5cca6f52122119b.html#add3a17b29e9908b6e5cca6f52122119b">keyboard</a>();</div><div class="line"></div><div class="line">  <span class="comment">//static fabgl::VirtualKey lastvk = fabgl::VK_NONE; // avoid to repeat last vk</span></div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (Serial.available() &gt; 0) {</div><div class="line">    <span class="keywordtype">char</span> c = Serial.read();</div><div class="line">    <span class="keywordflow">switch</span> (c) {</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;h&#39;</span>:</div><div class="line">        printHelp();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;1&#39;</span>:</div><div class="line">        keyboard-&gt;setLayout(&amp;fabgl::USLayout);</div><div class="line">        printInfo();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;2&#39;</span>:</div><div class="line">        keyboard-&gt;setLayout(&amp;fabgl::UKLayout);</div><div class="line">        printInfo();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;3&#39;</span>:</div><div class="line">        keyboard-&gt;setLayout(&amp;fabgl::GermanLayout);</div><div class="line">        printInfo();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;4&#39;</span>:</div><div class="line">        keyboard-&gt;setLayout(&amp;fabgl::ItalianLayout);</div><div class="line">        printInfo();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;5&#39;</span>:</div><div class="line">        keyboard-&gt;setLayout(&amp;fabgl::SpanishLayout);</div><div class="line">        printInfo();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;6&#39;</span>:</div><div class="line">        keyboard-&gt;setLayout(&amp;fabgl::FrenchLayout);</div><div class="line">        printInfo();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;7&#39;</span>:</div><div class="line">        keyboard-&gt;setLayout(&amp;fabgl::BelgianLayout);</div><div class="line">        printInfo();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;r&#39;</span>:</div><div class="line">        keyboard-&gt;reset();</div><div class="line">        printInfo();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;l&#39;</span>:</div><div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 8; ++i) {</div><div class="line">          keyboard-&gt;setLEDs(i &amp; 1, i &amp; 2, i &amp; 4);</div><div class="line">          delay(1000);</div><div class="line">        }</div><div class="line">        delay(2000);</div><div class="line">        <span class="keywordflow">if</span> (keyboard-&gt;setLEDs(0, 0, 0))</div><div class="line">          xprintf(<span class="stringliteral">&quot;OK\r\n&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;q&#39;</span>:</div><div class="line">        keyboard-&gt;setScancodeSet(1);</div><div class="line">        xprintf(<span class="stringliteral">&quot;Scancode Set = %d\r\n&quot;</span>, keyboard-&gt;scancodeSet());</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;w&#39;</span>:</div><div class="line">        keyboard-&gt;setScancodeSet(2);</div><div class="line">        xprintf(<span class="stringliteral">&quot;Scancode Set = %d\r\n&quot;</span>, keyboard-&gt;scancodeSet());</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    }</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (keyboard-&gt;virtualKeyAvailable()) {</div><div class="line">    <span class="comment">// ascii mode (show ASCIIl, VirtualKeys and scancodes)</span></div><div class="line">    VirtualKeyItem item;</div><div class="line">    <span class="keywordflow">if</span> (keyboard-&gt;getNextVirtualKey(&amp;item)) {</div><div class="line">      xprintf(<span class="stringliteral">&quot;%s: &quot;</span>, keyboard-&gt;virtualKeyToString(item.vk));</div><div class="line">      xprintf(<span class="stringliteral">&quot;\tASCII = 0x%02X\t&quot;</span>, item.ASCII);</div><div class="line">      <span class="keywordflow">if</span> (item.ASCII &gt;= <span class="charliteral">&#39; &#39;</span>)</div><div class="line">        xprintf(<span class="stringliteral">&quot;&#39;%c&#39;&quot;</span>, item.ASCII);</div><div class="line">      xprintf(<span class="stringliteral">&quot;\t%s&quot;</span>, item.down ? <span class="stringliteral">&quot;DN&quot;</span> : <span class="stringliteral">&quot;UP&quot;</span>);</div><div class="line">      xprintf(<span class="stringliteral">&quot;\t[&quot;</span>);</div><div class="line">      <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 8 &amp;&amp; item.scancode[i] != 0; ++i)</div><div class="line">        xprintf(<span class="stringliteral">&quot;%02X &quot;</span>, item.scancode[i]);</div><div class="line">      xprintf(<span class="stringliteral">&quot;]&quot;</span>);</div><div class="line">      xprintf(<span class="stringliteral">&quot;\r\n&quot;</span>);</div><div class="line">    }</div><div class="line">  }</div><div class="line"></div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Mon Aug 2 2021 07:08:02 for FabGL by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>
  </ul>
</div>
</body>
</html>
